package com.hpjz.common.web;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.ArrayUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

import com.hpjz.common.json.JSONUtils;
import com.hpjz.common.log.LogUtils;

/**
 * 日志切面，请求日志进行处理
 * 
 * @author bbchen
 *
 */
@Aspect
public class LogAspect {
	
	@Pointcut("execution(public * com.hpjz.*.web.controller.*Controller.*(..))")
	public void pointcut(){
		
	}
	
	
	@Around(value="pointcut()")
    public Object aroundLog(ProceedingJoinPoint point) throws Throwable{
    	HttpServletRequest requst = HttpUtils.getHttpServletRequest();
    	String url = requst.getRequestURL().toString();
    	Object[] objs = point.getArgs();
    	 
    	 
    	Object params = ArrayUtils.isEmpty(objs)?null:point.getArgs()[0];
    	
    	LogUtils.info("接口{}请求参数是:{}",url,JSONUtils.objectToJson(params));
    	
        //请求返回值
    	Object value = point.proceed();
    	LogUtils.info("接口{}请求返回值:{}",url,JSONUtils.objectToJson(value));
		return value;
    }

}
